﻿namespace HuaWei.CommClass
{
    using Microsoft.JScript;
    using Microsoft.JScript.Vsa;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public static class CHelp
    {
        public static string ClassToJson(object obj)
        {
            return "";
        }

        public static void ControlAddForm(Control c, Form frm, bool isShow)
        {
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.Dock = DockStyle.Fill;
            frm.TopLevel = false;
            frm.Width = c.Width;
            frm.Height = c.Height;
            c.Controls.Add(frm);
            if (isShow)
            {
                frm.Show();
            }
        }

        public static DateTime ConverDateTime(object o, [Optional, DefaultParameterValue(false)] bool isMax)
        {
            DateTime maxValue;
            if (isMax)
            {
                maxValue = DateTime.MaxValue;
            }
            else
            {
                maxValue = DateTime.MinValue;
            }
            if (((o != null) && (o != DBNull.Value)) && !o.Equals(""))
            {
                maxValue = System.Convert.ToDateTime(o);
            }
            return maxValue;
        }

        public static decimal ConvertDecimal(object o, [Optional, DefaultParameterValue(0)] int defaultValue, [Optional, DefaultParameterValue(0)] int digits)
        {
            double num = defaultValue;
            if (((o != null) && (o != DBNull.Value)) && !o.Equals(""))
            {
                num = System.Convert.ToDouble(o);
            }
            return System.Convert.ToDecimal(Math.Round(num, digits, MidpointRounding.AwayFromZero));
        }

        public static int ConvertInt(object o, [Optional, DefaultParameterValue(0)] int defaultValue)
        {
            int num = defaultValue;
            if (((o != null) && (o != DBNull.Value)) && !o.Equals(""))
            {
                num = System.Convert.ToInt16(o);
            }
            return num;
        }

        public static void CreateFile(string context, string filePath)
        {
            StreamWriter writer = File.CreateText(filePath);
            writer.Write(context);
            writer.Close();
        }

        public static void CreateFile(string name, string context, string ext)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + @"license\" + name + "." + ext;
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            CreateFile(context, path);
        }

        public static object EvalExpress(string sExpression)
        {
            VsaEngine engine = VsaEngine.CreateEngine();
            return Eval.JScriptEvaluate(sExpression, engine);
        }

        public static string ListToParam(List<string> list)
        {
            string str = "";
            foreach (string str2 in list)
            {
                if (!str.Equals(""))
                {
                    str = str + "#";
                }
                str = str + str2;
            }
            return str;
        }

        public static void openMdiFrm(Form sender, Form openFrm)
        {
            openFrm.MdiParent = sender;
            openFrm.Show();
        }

        public static List<string> ParamToList(string param)
        {
            string[] strArray = param.Split(new char[] { '#' });
            List<string> list = new List<string>();
            foreach (string str in strArray)
            {
                list.Add(str);
            }
            return list;
        }

        public static string smethod(string sql)
        {
            int num;
            string str = sql;
        Label_0064:
            num = str.IndexOf("[");
            int index = str.IndexOf("]");
            int length = str.Length;
            if (num != -1)
            {
                string str3 = str.Substring(num + 1, (index - num) - 1);
                str = str.Substring(0, num) + "case when isnull(" + str3 + ")=1 then 0 else " + str3 + " end" + str.Substring(index + 1);
                goto Label_0064;
            }
            return str;
        }

        public static string smethod1(string sql)
        {
            int num;
            string str = sql;
        Label_0064:
            num = str.IndexOf("[");
            int index = str.IndexOf("]");
            int length = str.Length;
            if (num != -1)
            {
                string str3 = str.Substring(num + 1, (index - num) - 1);
                str = str.Substring(0, num) + "case when " + str3 + "=0  then 0.01 else " + str3 + " end" + str.Substring(index + 1);
                goto Label_0064;
            }
            return str;
        }

        public static string ToAdd0(string value, [Optional, DefaultParameterValue(3)] int leng)
        {
            string str = value;
            int length = value.Length;
            for (int i = 0; i < (leng - length); i++)
            {
                str = "0" + str;
            }
            return str;
        }
    }
}

